﻿using System;
using System.Configuration;

namespace Rarous.TexyNet.Configuration {
  /// <summary>
  /// 
  /// </summary>
  public class ConfigSectionHandler : ConfigurationSection {
    #region Constructors
    /// <summary>
    /// Konstruktor
    /// </summary>
    public ConfigSectionHandler()
      : base() {
    }
    #endregion

    #region Properties
    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("providers")]
    public ProviderSettingsCollection Providers {
      get {
        return base["providers"] as ProviderSettingsCollection;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("defaultProvider", DefaultValue = "xml-rpc")]
    [StringValidator(MinLength = 1)]
    public string DefaultProvider {
      get {
        return base["defaultProvider"] as String;
      }
      set {
        base["defaultProvider"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("safeMode", IsRequired = false, DefaultValue = false)]
    public bool SafeMode {
      get {
        return Convert.ToBoolean(this["safeMode"]);
      }
      set {
        this["safeMode"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("singleLine", IsRequired = false, DefaultValue = false)]
    public bool SingleLine {
      get {
        return Convert.ToBoolean(this["singleLine"]);
      }
      set {
        this["singleLine"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("obfuscateEmail", IsRequired = false, DefaultValue = false)]
    public bool ObfuscateEmail {
      get {
        return Convert.ToBoolean(this["obfuscateEmail"]);
      }
      set {
        this["obfuscateEmail"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("mergeLines", IsRequired = false, DefaultValue = false)]
    public bool MergeLines {
      get {
        return Convert.ToBoolean(this["mergeLines"]);
      }
      set {
        this["mergeLines"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("smilesModule", IsRequired = false)]
    public SmilesModuleElement SmilesModule {
      get {
        return this["smilesModule"] as SmilesModuleElement;
      }
      set {
        this["smilesModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("quoteModule", IsRequired = false)]
    public QuoteModuleElement QuoteModule {
      get {
        return this["quoteModule"] as QuoteModuleElement;
      }
      set {
        this["quoteModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("linkModule", IsRequired = false)]
    public LinkModuleElement LinkModule {
      get {
        return this["linkModule"] as LinkModuleElement;
      }
      set {
        this["linkModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("imageModule", IsRequired = false)]
    public ImageModuleElement ImageModule {
      get {
        return this["imageModule"] as ImageModuleElement;
      }
      set {
        this["imageModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("imageDescriptionModule", IsRequired = false)]
    public ImageDescriptionModuleElement ImageDescriptionModule {
      get {
        return this["imageDescriptionModule"] as ImageDescriptionModuleElement;
      }
      set {
        this["imageDescriptionModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("headingModule", IsRequired = false)]
    public HeadingModuleElement HeadingModule {
      get {
        return this["headingModule"] as HeadingModuleElement;
      }
      set {
        this["headingModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("formatterModule", IsRequired = false)]
    public FormatterModuleElement FormatterModule {
      get {
        return this["formatterModule"] as FormatterModuleElement;
      }
      set {
        this["formatterModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("blockModule", IsRequired = false)]
    public BlockModuleElement BlockModule {
      get {
        return this["blockModule"] as BlockModuleElement;
      }
      set {
        this["blockModule"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("allowedClasses", IsDefaultCollection = false, IsRequired = false)]
    [ConfigurationCollection(typeof(StringElement))]
    public StringElementCollection AllowedClasses {
      get {
        return this["allowedClasses"] as StringElementCollection;
      }
      set {
        this["allowedClasses"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("allowedStyles", IsDefaultCollection = false, IsRequired = false)]
    [ConfigurationCollection(typeof(StringElement))]
    public StringElementCollection AllowedStyles {
      get {
        return this["allowedStyles"] as StringElementCollection;
      }
      set {
        this["allowedStyles"] = value;
      }
    }

    /// <summary>
    /// 
    /// </summary>
    [ConfigurationProperty("allowedTags", IsDefaultCollection = false, IsRequired = false)]
    [ConfigurationCollection(typeof(TagElement))]
    public TagElementCollection AllowedTags {
      get {
        return this["allowedTags"] as TagElementCollection;
      }
      set {
        this["allowedTags"] = value;
      }
    }
    #endregion

    #region Override Methods
    /// <summary>
    /// Nastavuje výchozí hodnoty
    /// </summary>
    protected override void InitializeDefault() {
      base.InitializeDefault();
      SafeMode = false;
      SingleLine = false;
      ObfuscateEmail = false;
      MergeLines = false;
      SmilesModule = new SmilesModuleElement();
      QuoteModule = new QuoteModuleElement();
      BlockModule = new BlockModuleElement();
      HeadingModule = new HeadingModuleElement();
      LinkModule = new LinkModuleElement();
      ImageDescriptionModule = new ImageDescriptionModuleElement();
      ImageModule = new ImageModuleElement();
      FormatterModule = new FormatterModuleElement();
      AllowedClasses = new StringElementCollection();
      AllowedStyles = new StringElementCollection();
      AllowedTags = new TagElementCollection();
    }
    #endregion
  }
}
